package com.qf.test;

import com.qf.interfaces.FangDongInterface;
import com.qf.staticProxy.FangDongImpl;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @ClassName textcglib
 * @Author xiao宋
 * @Date 20:52  2022/9/27
 * @Version 1.0
 * @Description TODO
 */
public class textCglib {
    public static void main(final String[] args) {
        final FangDongInterface fd=new FangDongImpl();
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(fd.getClass());
        enhancer.setCallback(new MethodInterceptor() {
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                System.out.println("中介要干的活");
                Object invoke = method.invoke(fd, args);

                return invoke;
            }
        });
        FangDongImpl pro=(FangDongImpl) enhancer.create();
        pro.zuFang();

    }
}
